package com.diy.sigmund.diyuser.test.controller;

import com.diy.sigmund.diycommon.entity.ResultMsg;
import com.diy.sigmund.diycommon.entity.enumerate.VerifyParamPolicyEnum;
import com.diy.sigmund.diycommon.spring.anno.TestAnno;
import com.diy.sigmund.diycommon.spring.anno.VerifyParam;
import com.diy.sigmund.diycommon.spring.anno.VerifyParams;
import com.diy.sigmund.diycommon.test.entity.FormDataDTO;
import com.diy.sigmund.diycommon.test.entity.MqTestVO;
import com.diy.sigmund.diycommon.util.VerifyParamUtil;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ylm-sigmund
 * @since 2021/4/17 15:56
 */
@RestController
@RequestMapping("/verifyParamTest")
public class VerifyParamTestController {

    private static final Logger log = LoggerFactory.getLogger(VerifyParamTestController.class);

    @VerifyParams(value = {@VerifyParam(fieldName = "id"),
            @VerifyParam(fieldName = "name", verifyPolicy = VerifyParamPolicyEnum.NOT_BLANK, msg = "name不能为null啊啊啊啊啊嗄！！！！！"),
            @VerifyParam(fieldName = "phone", verifyPolicy = VerifyParamPolicyEnum.MATCHES, verifyValue = VerifyParamUtil.PHONE_PATTERN),
            @VerifyParam(fieldName = "email", verifyPolicy = VerifyParamPolicyEnum.MATCHES, verifyValue = VerifyParamUtil.EMAIL_PATTERN),
            @VerifyParam(fieldName = "idCard", verifyPolicy = VerifyParamPolicyEnum.MATCHES, verifyValue = VerifyParamUtil.IDCARD_PATTERN),
            @VerifyParam(fieldName = "aBoolean", verifyPolicy = VerifyParamPolicyEnum.ASSERT_TRUE),
            @VerifyParam(fieldName = "minInteger", verifyPolicy = VerifyParamPolicyEnum.MIN, verifyValue = "100"),
            @VerifyParam(fieldName = "maxInteger", verifyPolicy = VerifyParamPolicyEnum.MAX, verifyValue = "100"),
            @VerifyParam(fieldName = "betweenInteger", verifyPolicy = VerifyParamPolicyEnum.BETWEEN_INTEGER, verifyValue = "50,100"),
            @VerifyParam(fieldName = "pastDate", verifyPolicy = VerifyParamPolicyEnum.PAST, verifyValue = "2021-6-27 18:09:00"),
            @VerifyParam(fieldName = "futureDate", verifyPolicy = VerifyParamPolicyEnum.FUTURE, verifyValue = "2021-6-27 18:09:00"),
            @VerifyParam(fieldName = "betweenDate", verifyPolicy = VerifyParamPolicyEnum.BETWEEN_DATE, verifyValue = "2021-6-27 18:09:00,2021-6-27 23:09:00")})
    @PostMapping("/login")
    public ResultMsg login(@RequestBody @TestAnno FormDataDTO dtp, @TestAnno String param) {
        log.info("用户开始登录");
        MqTestVO mqTestVo = new MqTestVO();
        mqTestVo.setUserId(UUID.randomUUID().toString());
        mqTestVo.setPhoneNum(UUID.randomUUID().toString().substring(0, 11));
        return ResultMsg.success(mqTestVo);
    }

}
